<include file="Product:header"/>
<div class="main">

    	<div class="p_mod">
    		<h2 class="p_mod_title">购物车</h2>
            <div class="car">
                <volist name="products" id="p">
              <div class="car_list clearfix">
                <div class="car_content clearfix">
                  <h3><a href="{lanrain::U('Product/product',array('token'=>$_GET['token'],'id'=>$p['id'],'wecha_id'=>$_GET['wecha_id']))}">{lanrain:$p.name}</a></h3>
                     <a href="{lanrain::U('Product/product',array('token'=>$_GET['token'],'id'=>$p['id'],'wecha_id'=>$_GET['wecha_id']))}">
                      <img src="{lanrain:$p.logourl}" />
                     </a>
                     <div class="car_property">
                        <span class="price_now">单价：<font>￥{lanrain:$p.price}</font></span>
                                                <div class="o_num_input clearfix" id="{lanrain:$p.id}">
                            <a class="minus ts2" href="javascript:;" onclick="plus_minus({lanrain:$p.id}, -1,{lanrain:$p.price})">-</a>
                            <input type="number" min="1" lastnum="1" value="{lanrain:$p.count}" id="qty{lanrain:$p.id}" class="qty" onblur="full_update({lanrain:$p.id},{lanrain:$p.price})" />
                            <a class="plus ts2 on" href="javascript:;" onclick="plus_minus({lanrain:$p.id},1,{lanrain:$p.price})">+</a>
                        </div>
                        <a class="u_order_return delete" href="{lanrain::U('Product/deleteCart',array('token'=>$_GET['token'],'id'=>$p['id'],'wecha_id'=>$_GET['wecha_id']))}">删除商品</a>                     
                     </div>
                </div>
              </div>
                 </volist>
                            <p><span class="price_now" id="total_fee">总价格：<font>￥{lanrain:$totalFee}</font></span></p>
            </div>            
    	</div>
            	<div class="o_btn clearfix">
            	<if condition="$totalProductCount neq 0">
    		<input type="button" class="o_btn_back ts1" onclick="history.go(-1);" value="继续购物"/>
    		<input type="button" class="o_btn_submit ts1" onclick="location.href='{lanrain::U('Product/orderCart',array('token'=>$_GET['token'],'cartIsDining'=>$cartIsDining,'wecha_id'=>$_GET['wecha_id']))}'" value="去结算" />
    		</if>
    	</div>
 
</div>
<style type="text/css">
.desks{ display: none;}
</style>
<script type="text/javascript">
function full_update(rowid,price) {
    var _this = $('#qty'+rowid);
    var this_val = parseInt($(_this).val());
    if (this_val < 1 || isNaN(this_val)) {
        alert('购买数量不能小于0！');
        $(_this).focus();
        return false;
    }
    update_cart(rowid, this_val,price);
}
//加减
function plus_minus(rowid, number,price) {
    var num = parseInt($('#qty'+rowid).val());
    num = num + parseInt(number);
    if (num < 1) {
        return false;
    }
     $('#qty'+rowid).attr('value',num);
    update_cart(rowid, num,price);     
}

//更新购物车
function update_cart(rowid, num,price) {
	$.ajax({
		url: '{lanrain::U('Product/ajaxUpdateCart',array('token'=>$_GET['token'],'wecha_id'=>$_GET['wecha_id']))}&id='+rowid+'&count='+num+'&price='+price,
		success: function( data ) {
			if(data){
				var datas=data.split('|');
				$('#p_buy #all_price').html('￥'+datas[1]);
				$('#p_buy #all_numb').html(datas[0]);
				$('#total_fee font').html('￥'+datas[1]);
			}
		}
	});
}
//点击加入购物车
    function add_cart(id,price,count) {
    	$.ajax({
    		url: "{lanrain::U('Product/addProductToCart',array('token'=>$_GET['token'],'wecha_id'=>$_GET['wecha_id']))}"+'&id='+id+'&price='+price+'&count='+count,
    		success: function( data ) {
    			if(data){
    				var datas=data.split('|');
    				$('#p_buy #all_price').html('￥'+datas[1]);
                    $('#p_buy #all_numb').html(datas[0]); 
    			}
    		}
    	});
    }

  
</script>
</body>
</html>